<template>
  <div class="xmind-map-outline">
    <div class="mind-content">
      <div class="outline-title">
        <p>“{{ data?.name }}”</p>
      </div>
      <div class="content">
        <Tree :dataList="[copyRootTopic].filter(Boolean)" />
      </div>
      </div>
  </div>
</template>

<script setup>
import { ref, onBeforeUnmount, defineExpose } from 'vue'
import { shortcutKeydown, resetcutKeydown } from '../shortcut-key'
import Tree from './Tree.vue'

const data = ref(null)
const copyRootTopic = ref(null)

function getNewMindJson () {
  return JSON.stringify(data.value.rootTopic) !== JSON.stringify(copyRootTopic.value) ? {
    ...data.value,
    rootTopic: copyRootTopic.value
  } : null
}

function setData (xmindJson) {
  data.value = xmindJson
  copyRootTopic.value = JSON.parse(JSON.stringify(data.value.rootTopic))
}

resetcutKeydown()

onBeforeUnmount(() => {
  shortcutKeydown()
})

defineExpose({
  getNewMindJson,
  setData
})
</script>

<style lang="scss" scoped>
.xmind-map-outline {
  position: fixed;
  background-color: #fff;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  z-index: 8;
  overflow: hidden;
  transform-origin: 100px 100%;
  box-shadow: inset 0px 0px 3px 0px rgba(255, 255, 255, 0.1), 0px 0px 3px 0px rgba(0, 0, 0, 0.14), 0px 8px 40px 0px rgba(0, 0, 0, 0.06);
  .mind-content {
    max-width: 890px;
    min-width: 600px;
    margin: 80px auto 0;
    display: flex;
    flex-direction: column;
    padding-bottom: 160px;
    height: 100%;
    .outline-title {
      margin-bottom: 20px;
      p {
        padding: 0 36px;
        font-size: 15px;
        font-size: 16px;
        font-weight: 600;
      }
    }
    .content {
      padding: 0 24px;
      flex: 1;
      height: 0;
      overflow-y: scroll;
      &::-webkit-scrollbar {
        display: none;
      }
    }
  }
}
</style>
